package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import java.util.logging.Logger;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import com.example.framework.Groups;
import com.example.objects.GroupObject;

public class GroupCreationTests extends TestBase {

	private Logger log = Logger.getLogger("GroupCreationTests");

	@Test(dataProvider = "groupsFromFile", dataProviderClass = GroupDataGenerator.class)
	public void testValidGroupCanBeCreated(GroupObject validGroup)
			throws Exception {
		Groups oldList = app.getGroupHelper().getGroups();
		app.getGroupHelper().createGroup(validGroup);
		Groups newList = app.getGroupHelper().getGroups();
		assertThat(newList, equalTo(oldList.withAdded(validGroup)));
	}

	@AfterMethod
	public void testUiAndDbConformWithDb() {
		if (app.getProperty("ui.check") != null) {
			Groups modelList = app.getGroupHelper().getGroups();
			Groups uiList = app.getGroupHelper().getUiGroups();
			assertThat(uiList, equalTo(modelList));
		}
		if (app.getProperty("db.check") != null) {
			Groups modelList = app.getGroupHelper().getGroups();
			Groups dbList = app.getHibernateHelper().getGroups();
			assertThat(dbList, equalTo(modelList));
		}
	}
}